Dataviz with R

Ilya Kashnitsky

8 July 2019

We are doing the right thing here

Anscombe’s Quartet

Imgur

dino https://www.autodeskresearch.com/publications/samestats

Outline

  • Day 1: tydyverse, ggplot2 basics
  • Day 2: more advanced ggplot2, customization
  • Day 3: specific types of useful plots
  • Day 4: interactive dataviz
  • Day 5: maps in R

Examples of data visualization

https://jschoeley.shinyapps.io/hmdexp

http://bancdadesced.uab.es/population_change/

http://www.global-migration.info

https://ikashnitsky.github.io/2018/the-lancet-paper/

More

Dataviz principles

https://policyviz.com/2018/08/07/dataviz-cheatsheet/

https://ft-interactive.github.io/visual-vocabulary/

https://serialmentor.com/dataviz/

http://socviz.co/index.html

Jonas Shoeley’s slides

https://github.com/jschoeley/idem_viz

Tidyverse

The most influential R developer

Hadley Wickham

hadley

tidyverse

https://blog.rstudio.org/2016/09/15/tidyverse-1-0-0/

https://www.tidyverse.org/

tidy data

Wickham, H. (2014). Tidy Data. Journal of Statistical Software, 59(10). Retrieved from http://www.jstatsoft.org/v59/i10

Tidy data is a standard way of mapping the meaning of a dataset to its structure.

A dataset is messy or tidy depending on how rows, columns and tables are matched up with observations, variables and types.

In tidy data:

  1. Each variable forms a column.
  2. Each observation forms a row.
  3. Each type of observational unit forms a table.

Examples and exercises

Please follow me on the R script "day1-tidy.R"

Visualizing data with ggplot2

A bit more motivation

http://qz.com/316906/the-dude-map-how-american-men-refer-to-their-bros

https://www.granvillematheson.com/post/self-portrait/

https://fivethirtyeight.com/features/why-the-oldest-person-in-the-world-keeps-dying/

https://barcanumbers.wordpress.com/2018/12/06/who-are-the-best-finishers-in-contemporary-football/

More

Plotting systems in R?

  • base
  • lattice
  • ggplot2

“The winner takes it all”

cat

Strength of base plotting system

  • Usually, base knows how to plot an object
  • Extremely easy to use if you are happy with the default settings
  • BUT
  • Now ggplot2 has the autoplot function

What makes ggplot2 special?

“gg” means “Grammar of graphics”

http://www.springer.com/us/book/9780387245447

Extremely big and helpful community

  • Help
  • Examples
  • Rapid development
  • Extensions

http://www.ggplot2-exts.org/gallery/

Amazing documentation

http://docs.ggplot2.org/current

One last hint before we start coding

https://github.com/dreamRs/esquisse

ggplot2 show

Please follow me on “day1-ggplot2-basics.R